<template>
  <div style="height: 100%;width:100%;display: flex;">
    <div class="left">
      <img class="image" src="@/assets/images/background.jpg">
    </div>
    <div class="right">
      <el-card class="card">
        <div class="title">高校教务系统-登录页面</div>
        <el-input v-model="userLoginForm.username" class="input" placeholder="输入你的账户" />
        <el-input v-model="userLoginForm.password" type="password" class="input" placeholder="输入你的密码" />
        <div class="login-button" @click="login()"><el-icon><Right /></el-icon></div>
        <el-radio-group class="radio" v-model="radio">
          <el-radio :label="0">学生</el-radio>
          <el-radio :label="1">教师</el-radio>
        </el-radio-group>
        <a style="color:#888888;margin-left: 40%;font-size: 13px;cursor: pointer;" @click="gotoRegister">去注册</a>
      </el-card>
    </div>
  </div>
</template>

<script setup lang="ts">
import {reactive, ref} from 'vue';
import { useRouter } from 'vue-router'
import {useUserStoreHook} from "@/store/modules/user";
import {useTeacherStoreHook} from "@/store/modules/teacher";
import {reqLoginForm} from "@/api/user/type";
import {TeacherLoginForm} from "@/api/teacher/type";
import {teacherLogin} from "@/api/teacher";
const userStore = useUserStoreHook()
const teacherStore = useTeacherStoreHook()
const router = useRouter()
const userLoginForm = reactive<reqLoginForm>({
    username: '',
    password: ''
})
// const teacherLoginForm = reactive<TeacherLoginForm>({
//   username: '',
//   password: ''
// })
const radio = ref(0)
const gotoRegister = () => {
  router.push('/register')
}

const login = async() => {
  if (radio.value === 0) {
    try {
       await userStore.login(userLoginForm)
    } catch (error) {
      await Promise.reject(error)
    }
    // console.log('学生登录')
  } else if (radio.value === 1){
    //教师登录逻辑
      try {
        await teacherStore.login(userLoginForm)
      } catch (error) {
        await Promise.reject(error)
      }
      // console.log('教师登录')
    }

}
</script>

<style scoped>
.left {
  height:100%;
  width:62%;
  display: inline-block;
}
.image {
  width:100%;
  height: 100vh;
}
.right {
  height:100vh;
  width:38%;
  display: inline-block;
  background-color: white;
}
.card {
  width:450px;
  height:360px;
  margin: 0 auto;
  margin-top: 35%;
}
.title {
  margin-top: 10px;
  font-weight: bold;
  font-size: 20px;
  text-align: center;
  margin-bottom: 45px;
}
.input {
  margin-left: 10%;
  height: 45px;
  margin-bottom: 20px;
  width:80%;
}

.login-button {
  margin: 0 auto;
  margin-top: 10px;
  background-color: #409EFF;
  width:60px;
  height:60px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  color:white;
  font-size: 30px;
  font-weight: bold;
  cursor: pointer;
}
.radio {
  margin-top: 10px;
  margin-left: 10%;
}
</style>
